import 'package:flutter/material.dart';
import 'package:flutter_project/config/app_bar_view.dart';
import 'package:flutter_project/config/theme_color.dart';
import '../user_login/user_info_model.dart';
import 'package:flutter_project/common/utils/extension_utils.dart';

class UserEditInfo extends StatelessWidget {
  final UserInfoRespModel infoRespModel;

  const UserEditInfo({required this.infoRespModel, super.key});

  @override
  Widget build(BuildContext context) {
    return CommonAppWidget.navAppBar(
      title: '个人资料',
      childWidget: ListView(
        children: [
          const SizedBox(
            height: 14,
          ),
          getUserAvatar(),
          Container(
            height: 0.5,
            color: ThemeColor.lineColor,
          ),
          getUserSex(leftName: '性别', rightName: isMan ? '男' : '女'),
          Container(
            height: 0.5,
            color: ThemeColor.lineColor,
          ),
          getUserSex(
              leftName: '手机号',
              rightName: infoRespModel.phoneNum!
                  .getRightPhone(infoRespModel.phoneNum ?? '')),
        ],
      ),
    );
  }

  Widget getUserAvatar() {
    String sexStr = infoRespModel.gender == 1
        ? 'assets/images/as_avatar_man.png'
        : 'assets/images/as_avatar_woman.png';
    return Container(
      color: Colors.white,
      padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 10),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          const Text('头像'),
          Image.asset(
            sexStr,
            width: 60,
          ),
        ],
      ),
    );
  }

  bool get isMan {
    return infoRespModel.gender == 1 ? true : false;
  }

  Widget getUserSex({
    required String leftName,
    required String rightName,
  }) {
    return Container(
      color: Colors.white,
      padding: const EdgeInsets.symmetric(vertical: 20, horizontal: 10),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Text(leftName),
          Text(rightName),
        ],
      ),
    );
  }
}
